<!DOCTYPE HTML>
<html>
<head>
    <title>Error</title>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <script src="/scripts/jquery.min.js"></script>
    <link rel="stylesheet" href="/stylesheets/formdata.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">

    <script src="/scripts/miniui/miniui.js"></script>
    <script src="/qiniuJs/liveFormdata.js"></script>
    <script src="/qiniuJs/livePicFormdata.js"></script>

</head>
<body>
<!--<div class="container" style="display: inline-block;width: 40%; margin: 10px">-->
<!--&lt;!&ndash; Document：https://developer.qiniu.com/kodo/manual/form-upload &ndash;&gt;-->
<!--<form id="testform" method="post" enctype="multipart/form-data">-->
<!--<input name="key" id="key" type="hidden" value="">-->
<!--&lt;!&ndash;<input id="userfile" name="file"  accept="audio/mp4,video/mp4"   type="file" />&ndash;&gt;-->
<!--&lt;!&ndash;<input name="accept" type="hidden" />&ndash;&gt;-->
<!--</form>-->
<!--&lt;!&ndash; add file &ndash;&gt;-->
<!--<label for="userfile">-->
<!--<span></span>-->
<!--<em>添加视频</em>-->
<!--</label>-->

<!--&lt;!&ndash; upload info &ndash;&gt;-->
<!--<div class="selected-file"></div>-->
<!--<div class="progress"></div>-->
<!--<div class="uploaded-result"></div>-->
<!--</div>-->
<div class="container" style="display: inline-block;width: 95%;">
    <form id="testformPic" method="post" enctype="multipart/form-data">
        <input name="key" id="keyPic" type="hidden" value="">
        <input name="token" type="hidden" value="<%= uptokenPic %>">
        <input id="userfilePic" name="file" style="display: none" accept="image/*" type="file"/>
        <input name="accept" type="hidden"/>
    </form>
    <!-- add file -->
    <label for="userfilePic">
        <span></span>
        <em>添加封面</em>
    </label>

    <!-- upload info -->
    <div class="selected-file-pic"></div>
    <div class="progress-pic"></div>
    <div class="uploaded-result-pic"></div>
</div>
<div id="form1" style="padding-left: 30px">
    <span style="width:80px;display:inline-block;">标题：</span>
    <input id="title" name="title" class="mini-textbox" required="true" style="width:155px;"/>

    <span style="width:80px;display:inline-block;">部落：</span>
    <input id="tribeOId" class="mini-buttonedit" onbuttonclick="onButtonEdit" name="a" textName="b"/>

    <br/><br/>

    <span style="width:80px;display:inline-block;">一级分享：</span>
    <input id="firstLevel" class="mini-textbox" vtype="float" style="width:155px;"/>

    <span style="width:80px;display:inline-block;">二级分享：</span>
    <input id="lastLevel" name="title" class="mini-textbox" vtype="float" style="width:155px;"/>

    <br/><br/>

    <span style="width:80px;display:inline-block;">创建人：</span>
    <input id="createrOId" class="mini-buttonedit" onbuttonclick="onButtonUser" name="a" textName="b"/>

    <span style="width:80px;display:inline-block;">公开：</span>
    <input id="isPublic" name="title" class="mini-combobox" required="true" style="width:155px;" data="isPublic"/>
    <!--<input id="streambackup"  required="true"  class="mini-textbox" style="display: none"/>-->
    <input id="coverPic" required="true" class="mini-textbox" style="display: none"/>

    <br/><br/>
    <div style="margin: 0 auto;text-align: center">
        <a class="mini-button " iconCls="icon-ok" onclick="updataShop()">确定</a>
        <a class="mini-button" iconCls="icon-cancel" onclick="onCancel">取消</a>
    </div>
</div>
</body>
<script>
  var domain = "<%- domain %>";
  var isPublic = [{id: 1, text: "公开"}, {id: 0, text: "私有"}];

  function updataShop() {
    var form = new mini.Form("#form1");
    form.validate();
    if (form.isValid() == false) {
      alert("请正确填写数据")
      return
    }
    ;
    var title = mini.get("title").getValue();
    var tribeOId = mini.get("tribeOId").getValue();
    var createrOId = mini.get("createrOId").getValue();
    var isPublic = mini.get("isPublic").getValue();
//    var streambackup = mini.get("streambackup").getValue();
    var coverPic = mini.get("coverPic").getValue();
    var firstLevel = mini.get("firstLevel").getValue();
    var lastLevel = mini.get("lastLevel").getValue();
    var status = 2;//-1删除0禁播1预约2中3结束4录播
    var isRecord = 4;//1是录播，0直播，2上传,3定时直播，4设备直播
    var goods = [];

    $.ajax({
      type: "POST",
      url: "/getdata/createLiveForDevice",
      data: {
        title: title,
        tribeOId: tribeOId,
        createrOId: createrOId,
        isPublic: isPublic,
        status: status,
        isRecord: isRecord,
        coverPic: coverPic,
        firstLevel: firstLevel,
        lastLevel: lastLevel,
        browseNum: 0,
        goods: goods,
      },

      success: function (result) {
//        console.log(result)
        if (result == '1'){
          CloseWindow("save");
        }
      },
      fail: function (error) {
        console.log(error)
//        CloseWindow("close");
      }
    })
  }

  //    关闭窗口
  function CloseWindow(action) {
    if (action == "close" && form.isChanged()) {
      if (confirm("数据被修改了，是否先保存？")) {
        return false;
      }
    }
    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
    else window.close();
  }

  function onOk(e) {
    SaveData();
  }

  function onCancel(e) {
    CloseWindow("cancel");
  }

  function onButtonEdit(e) {
    var btnEdit = this;
    mini.open({
      url: "/editor/tribeChoice",
      title: "选择列表",
      width: 700,
      height: 450,
      ondestroy: function (action) {
        if (action == "ok") {
          var iframe = this.getIFrameEl();
          var data = iframe.contentWindow.GetData();
          data = mini.clone(data);    //必须
          if (data) {
            btnEdit.setValue(data.id);
            btnEdit.setText(data.text);
          }
        } else {
          btnEdit.setText("");
          btnEdit.setValue("");
        }

      }
    });

  }

  function onButtonUser(e) {
    var btnEdit = this;
    mini.open({
      url: "/tribeRoute/tribeMGEditSelectCreater",
      title: "选择列表",
      width: 700,
      height: 450,
      ondestroy: function (action) {
        //if (action == "close") return false;
        if (action == "ok") {
          var iframe = this.getIFrameEl();
          var data = iframe.contentWindow.GetData();
          data = mini.clone(data);    //必须
          if (data) {
            btnEdit.setText(data.nickName);
            btnEdit.setValue(data.objectId);
          }
        }

      }
    });

  }

</script>
</html>